package com.xjl.example.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.*;

/**
 * 如果需要返回值  就实现一个callable接口
 * Created by xiaojinlu1990@163.com on 2019/12/26.
 */
@Slf4j
public class FuturExample {

    static class LearnTask implements Callable<String>{

        @Override
        public String call() throws Exception {

            return UUID.randomUUID().toString();
        }
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService service = Executors.newCachedThreadPool();
        List<String> list =  new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            Future<String> submit  = service.submit(new LearnTask());
            list.add(submit.get());
            log.info("{}",i);
        }
        for (int i = 0; i < list.size(); i++) {
            log.info(list.get(i));

        }
    }

}
